{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "2960ee13-ecc9-46d1-b09f-1132da5154ea",
   "metadata": {},
   "outputs": [],
   "source": [
    "from openai import OpenAI"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "48368d7d-b663-4c8a-9870-ffb5f3a8b928",
   "metadata": {},
   "outputs": [],
   "source": [
    "client = OpenAI()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "65706720-a93c-4ee8-919b-098e00246229",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "姓名: 张三\n",
      "年龄: 27\n",
      "客户ID: 001\n"
     ]
    }
   ],
   "source": [
    "response = client.chat.completions.create(\n",
    "  model=\"gpt-3.5-turbo\",\n",
    "  messages=[\n",
    "    {\n",
    "      \"role\": \"user\",\n",
    "      \"content\": \"格式化以下信息：\\n姓名 -> 张三\\n年龄 -> 27\\n客户ID -> 001\"\n",
    "    }\n",
    "  ]\n",
    ")\n",
    "print(response.choices[0].message.content)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "118a3434-407a-4161-ac06-335563e2c68c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'## 客户信息\\n- 客户姓名：王五\\n- 客户年龄：32岁\\n- 客户ID：003'"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "response = client.chat.completions.create(\n",
    "  model=\"gpt-3.5-turbo\",\n",
    "  messages=[\n",
    "    {\n",
    "      \"role\": \"user\",\n",
    "      \"content\": \"格式化以下信息：\\n姓名 -> 张三\\n年龄 -> 27\\n客户ID -> 001\"\n",
    "    },\n",
    "    {\n",
    "      \"role\": \"assistant\",\n",
    "      \"content\": \"##客户信息\\n- 客户姓名：张三\\n- 客户年龄：27岁\\n- 客户ID：001\"\n",
    "    },\n",
    "    {\n",
    "      \"role\": \"user\",\n",
    "      \"content\": \"格式化以下信息：\\n姓名 -> 李四\\n年龄 -> 42\\n客户ID -> 002\"\n",
    "    },\n",
    "    {\n",
    "      \"role\": \"assistant\",\n",
    "      \"content\": \"##客户信息\\n- 客户姓名：李四\\n- 客户年龄：42岁\\n- 客户ID：002\"\n",
    "    },\n",
    "    {\n",
    "      \"role\": \"user\",\n",
    "      \"content\": \"格式化以下信息：\\n姓名 -> 王五\\n年龄 -> 32\\n客户ID -> 003\"\n",
    "    }\n",
    "  ]\n",
    ")\n",
    "response.choices[0].message.content"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fdb55640-871d-49eb-ab23-89a37a5a3bb6",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
